﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Xml.XmlDocument>" %>

<%= Documents.Common.Helpers.XmlHelper.TransformXML(Model,Server.MapPath(@"~\Transforms\CareEvents.xslt")) %>

<script type="text/javascript">
    $("#careevents .careevent").click(function() {
        CareEventClick($(this));
        $("#careevents .selected").removeClass("selected");
        $(this).addClass("selected");
    });

    $("#createdocumentbutton").click(function() {
        if (!$(this).hasClass("disabled")) {
            var eventArgs = {documentType: $(this).attr("documenttype")};
            eventHub.RaiseEvent(DocumentEvents.OnDocumentCreate, eventArgs);
        }
    });

    function CareEventClick(item) {
        var careeventid = $(item).attr("careeventid");
        //$(".documenttypecontainer").attr("documenttype", dtype);
        eventHub.RaiseEvent(DocumentEvents.OnDocumentUnloading);
        var url = "/Home/CareEvent/" + careeventid;
            var ajaxOptions = {
                url: url,
                cache: false,
                type: "POST",
                success: LoadCareEventSuccess,
                error: LoadCareEventFailure
            };
            $.ajax(ajaxOptions);
        }
   /*
    function CategoryClickSync(item) {
        var url = "/Home/Documents/" + $(item).attr("categoryid");
            var ajaxOptions = {
                url: url,
                async: false,
                cache: false,
                type: "POST",
                success: LoadDocumentListSuccess,
                error: LoadDocumentListFailure
            };
            $.ajax(ajaxOptions);
        }

        function CategoryClick(item) {
            if ($(item).hasClass("documenttype"))
                return;
            var url = "/Home/Documents/" + $(item).attr("categoryid");
            var ajaxOptions = {
                url: url,
                cache: false,
                type: "POST",
                success: LoadDocumentListSuccess,
                error: LoadDocumentListFailure
            };
            $.ajax(ajaxOptions);
        }
    */
        function LoadCareEventSuccess(data) {
        // Update Document list
        $("#centerlist").html(data);
        // Hide history
        $("#historycontainer").addClass("hidden");
        // Update Document
        $("#documentcontainer").html("<h2>Unloaded</h2>");
        // Show document
        $("#documentcontainer").removeClass("hidden");
        eventHub.RaiseEvent(DocumentEvents.OnDocumentUnloaded);
        
    };

    function LoadCareEventFailure(xhr, description, error) {
        // log it, or do something...
    };
</script>
